#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, id;
int a[N];
void solve() {
  cin >> id >> n;
  cout << id << ' ' << (n + 1) / 2;
  rep(i, 1, n) cin >> a[i];
  priority_queue<int> mn;
  priority_queue<int, vector<int>, greater<int>> mx;
  rep(i, 1, n) {
    if (mx.size() && a[i] > mx.top())
      mx.push(a[i]);
    else
      mn.push(a[i]);
    while (mx.size() > i / 2) {
      int x = mx.top();
      mx.pop();
      mn.push(x);
    }
    while (mx.size() < i / 2) {
      int x = mn.top();
      mn.pop();
      mx.push(x);
    }
    if (i & 1) {
      int j = (i + 1) / 2;
      if (j % 10 == 1) cout << endl;
      cout << mn.top() << ' ';
    }
  }
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}